//
// Created by zuo on 2024/6/30.
// 题目链接 https://www.lanqiao.cn/problems/1113/learning/?page=1&first_category_id=1&problem_id=1113
//

#include<bits/stdc++.h>
using namespace std;

int main()
{
    // 增加 cin cout 的速度 固定写法
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int M;
    queue<string> V, N;
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        string f; // IN OUT
        string name; // name
        string op; // V N
        cin >> f;
        if (f == "IN")
        {
            cin >> name >> op;
            if (op == "V") V.push(name);
            else N.push(name);
        }
        else if (f == "OUT")
        {
            cin >> op;
            if (op == "V") V.pop();
            else N.pop();
        }
    }

    while (V.size())
    {
        cout << V.front() << '\n';
        V.pop();
    }
    while (N.size())
    {
        cout << N.front() << '\n';
        N.pop();
    }

    return 0;
}
